using UnityEngine;
using System;
using System.Collections;

public class SpotOrbit : MonoBehaviour
{
	public Transform target;
	public Transform cam;
	public Vector3 offset = new Vector3(3.0f, 3.0f, 0) + Vector3.up;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update ()
	{
		if (!target)
			return;

		cam = Camera.main.transform;
		Vector3 pt = cam.transform.position - target.position;
		double distance = Math.Sqrt(Math.Pow(pt.x, 2) + Math.Pow(pt.y, 2) + Math.Pow(pt.z, 2));

		if (distance < 25.0)
		{
			transform.position = target.transform.position + (cam.transform.position - target.position) / 2;
			transform.LookAt(target);
		}
	}
}
